package vcp.gui.secure.screens;

import javax.swing.JPanel;
import javax.swing.GroupLayout;
import javax.swing.SwingUtilities;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.TitledBorder;
import javax.swing.JSplitPane;
import javax.swing.JToolBar;

import vcp.gui.components.VCPFrame;
import vcp.gui.components.VCPMenu;
import vcp.gui.components.VCPPanel;
import vcp.gui.forms.LoginForm;
import vcp.gui.frames.GuestFrame;
import vcp.gui.utils.MenuBuilder;

import javax.swing.UIManager;
import javax.swing.JButton;

public class ScreenSwitchCombo extends VCPPanel {
	private VCPPanel pnlLeft;
	private VCPPanel pnlRight;
	private VCPMenu menu;	
	private GroupLayout groupLayout;
	private VCPPanel pnl;
	/**
	 * Create the panel.
	 * @param vcpMenu 
	 * @param pnl 
	 */
	public ScreenSwitchCombo(VCPMenu vcpMenu, VCPPanel pnl) {
		 initialize(vcpMenu,pnl);		  
	}
	
	private void initialize(VCPMenu vcpMenu,VCPPanel pnl){
		initContentPanes("Menu","Action");
		setDynamicPanel(pnl);
		setMenu(vcpMenu);
		initLayout();
	}

	private void initContentPanes(String strLeft,String strRight){
		if(pnlLeft==null && pnlRight==null){
		    pnlLeft = new VCPPanel();
		    pnlRight = new VCPPanel();
		    pnlLeft.setBorder(new TitledBorder(null, strLeft, TitledBorder.LEADING, TitledBorder.TOP, null, null));
		    pnlRight.setBorder(new TitledBorder(null, strRight, TitledBorder.LEADING, TitledBorder.TOP, null, null));		   
		}		
	}
	
	private void setDynamicPanel(VCPPanel pnl){
		if(pnl!=null)
		   this.pnl = pnl;	
	}
	
	private void setMenu(VCPMenu vcpMenu) {
		if(vcpMenu!=null){
		   this.menu = vcpMenu;
		   pnlLeft.add(vcpMenu);
		}
	}
	
	private void initLayout(){
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(pnlLeft, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(pnlRight, GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE)
					.addContainerGap())
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addComponent(pnlRight, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)
						.addComponent(pnlLeft, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE))
					.addContainerGap())
		);
		
		JButton btnNewButton = new JButton("New button");
		GroupLayout gl_pnlRight = new GroupLayout(pnlRight);
		gl_pnlRight.setHorizontalGroup(
			gl_pnlRight.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_pnlRight.createSequentialGroup()
					.addContainerGap()
					.addComponent(pnl)
					.addContainerGap(397, Short.MAX_VALUE))
		);
		gl_pnlRight.setVerticalGroup(
			gl_pnlRight.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_pnlRight.createSequentialGroup()
					.addContainerGap()
					.addComponent(pnl)
					.addContainerGap(221, Short.MAX_VALUE))
		);
		pnlRight.setLayout(gl_pnlRight);
		setLayout(groupLayout);
	}

	public GroupLayout getGroupLayout() {
		return groupLayout;
	}

	public void setGroupLayout(GroupLayout groupLayout) {
		this.groupLayout = groupLayout;
	}
}
